/**
 * Created by sxwu on 14-2-15.
 */


var log = require("../lib/log");
var config = require('../config');
var customerlog = require('../models/customerlog');
var virapinfo = require('../models/virapinfo');
var crypto = require('crypto');
var RUtil = require('./dataformatUtil');
//var domain = require('domain');


var status="error";

exports.index = function(request, response){
    request.session.lastpage="statadvisit.html";
    if(request.session.admin==undefined)
    {
        response.redirect("login.html");
    }
    else
    {

        var method = request.method || '';
        var data = RUtil.ap_data(request);
        data.front_data.title = '看看我的访问量';
        data.front_data.subtitle='广告点击量统计';
        data.front_data.usernick =request.session.admin.usernick;
        data.front_data.usertype =request.session.admin.usertype;


        if(method.toUpperCase() === "GET") {
            /*//查找ap列表，返回
            virapinfo.select(request.session.admin.userid, function(error,results) {
                if((error)!== null)
                {
                    // 数据库异常
                    data.front_data.errDesp = "查询失败：系统内部错误(错误码："+error.errno+")";
                    data.front_data.status="danger";
                    response.render("statadvisit", data);

                }
                else if(results.length <= 0) {
                    // 不存在，直接响应页面
                    data.front_data.errDesp = "您还没有添加任何AP设备，没有相应的统计信息。";
                    data.front_data.status="success";
                    response.render("statadvisit", data);
                } else {
                    //存在数据将数据发到页面
                    data.apinfo=results;
                    response.render("statadvisit", data);
                }

            });*/
            response.render("statadvisit", data);
        }

        else if(method.toUpperCase() === "POST")
        {
            response.send('拒绝访问');
        }
    }
};
